<div role="navigation" class="navbar navbar-default topnav">
  <div class="container clearfix">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a href="/" class="navbar-brand">
        <img src="{{ cdn('assets/images/logo4.png') }}" alt="DSPSTACK.COM" />
      </a>
    </div>
    <div id="top-navbar-collapse" class="collapse navbar-collapse clearfix">
      <div class="nav clearfix navbar-nav {{Auth::check() ? 'navbar-nav-div-logining' : ''}}" >
        <div class="fr">
          @if ((Request::is('users*') && isset($user)) || (Request::is('search*') && $user->id > 0))
            <form method="GET" action="{{ route('search') }}" accept-charset="UTF-8" class="navbar-form navbar-left">
              <div class="form-group">
                <input class="form-control search-input mac-style" placeholder="搜索范围：{{ $user->name }}" name="q" type="text" value="{{ (Request::is('search*') && isset($query)) ? $query : '' }}">
                <input class="form-control search-input mac-style"  name="user_id" type="hidden" value="{{ $user->id }}">
          @else
            <form method="GET" action="{{ route('search') }}" accept-charset="UTF-8" class="navbar-form navbar-left">
              <div class  ="form-group">
                <input class="form-control search-input mac-style" placeholder="搜索" name="q" type="text" value="{{ (Request::is('search*') && isset($query)) ? $query : '' }}">
          @endif
              </div>
            </form>
        
          <ul class="nav navbar-nav github-login" >
            @if (Auth::check())
              <li class="navbar-nav-eachli-logining">
                <a href="#" type="button" data-toggle="dropdown" style="background: none;" aria-haspopup="true" aria-expanded="false" >
                  <i class="fa fa-plus text-md"></i>
                </a>
                <ul class="dropdown-menu" aria-labelledby="dLabel">
                  <li>
                    <a class="button no-pjax" href="{{ URL::route('topics.create', ['category_id' => config('phphub.resources_id')]) }}">
                      <i class="fa fa-upload text-md"></i> 上传资源
                    </a>
                  </li>

                  <li>
                    <a class="button no-pjax" href="{{ route('articles.create') }}" >
                      <i class="fa fa-paint-brush text-md"></i> 创作文章
                    </a>
                  </li>

                  <li>
                    <a class="button no-pjax" href="{{ isset($category) ? URL::route('topics.create', ['category_id' => $category->id]) : URL::route('topics.create') }}">
                        <i class="fa fa-comment text-md"></i> 发起讨论
                    </a>
                  </li>
                  <li>
                    <a class="button no-pjax" href="{{ route('share_links.create', ['category_id' => config('phphub.hunt_category_id')]) }}">
                        <i class="fa fa-link text-md"></i> 分享链接
                    </a>
                  </li>
                  <li>
                    <a class="button no-pjax" href="{{ URL::route('topics.create', ['category_id' => config('phphub.homework_help_id')]) }}">
                        <i class="fa fa-question-circle text-md"></i> 提个问题
                    </a>
                  </li>
                </ul>
              </li>

              <li class="navbar-nav-eachli-logining">
                <a href="{{ route('notifications.unread') }}" class="text-warning" >
                  <span class="badge badge-{{ $currentUser->notification_count + $currentUser->message_count > 0 ? 'important' : 'fade' }} popover-with-html" data-content="消息提醒" id="notification-count">
                    {{ $currentUser->notification_count + $currentUser->message_count }}
                  </span>
                </a>
              </li>
              <li class="navbar-nav-eachli-logining navbar-nav-li-logining">
                <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="dLabel" >
                  <img class="avatar-topnav" alt="Summer" src="{{ $currentUser->present()->gravatar }}" />
                  <span class="login-name">{{{ $currentUser->name }}}</span>
                  <span class="caret"></span>
                </a>
                <ul class="dropdown-menu" aria-labelledby="dLabel">
                  @if (Auth::user()->can('visit_admin'))
                    <li>
                      <a href="/admin" class="no-pjax">
                        <i class="fa fa-tachometer text-md"></i> 管理后台
                      </a>
                    </li>
                  @endif

                  @if(Auth::user()->can('access_board'))
                    <li>
                      <a class="button" href="{{ route('categories.show', config('phphub.admin_board_cid')) }}">
                        <i class="fa fa-users "></i> 站务
                      </a>
                    </li>
                  @endif
                  <li>
                    <a class="button" href="{{ isset($currentUser->blog) ? route('blogs.show', $currentUser->blog->slug) : route('blogs.create') }}">
                      <i class="fa fa-hacker-news text-md"></i> 我的博客
                    </a>
                  </li>
                  <li>
                    <a class="button" href="{{ route('users.votes', $currentUser->id) }}">
                      <i class="fa fa-heart text-md"></i> 我的收藏
                    </a>
                  </li>
                  <li>
                    <a class="button" href="{{ route('users.show', $currentUser->id) }}">
                      <i class="fa fa-user text-md"></i> 个人中心
                    </a>
                  </li>
                  <li>
                    <a class="button" href="{{ route('users.charge_dcoin', $currentUser->id) }}">
                      <i class="fa fa-credit-card text-md"></i> 充D币
                    </a>
                  </li>
                  <li>
                    <a class="button" href="{{ route('users.edit', $currentUser->id) }}">
                      <i class="fa fa-cog text-md"></i> 编辑资料
                    </a>
                  </li>
                  <li>
                    <a id="login-out" class="button" href="{{ URL::route('logout') }}" data-lang-loginout="{{ lang('Are you sure want to logout?') }}">
                      <i class="fa fa-sign-out text-md"></i> {{ lang('Logout') }}
                    </a>
                  </li>
                </ul>
              </li> 

            @else
                <a href="{{ URL::route('auth.login') }}" class="btn btn-default login-btn no-pjax">
                  <i class="fa fa-user"></i>
                  {{ lang('Login') }}
                </a>
                <a href="{{ URL::route('auth.register') }}" class="btn btn-default login-btn no-pjax">
                    <i class="fa fa-user-plus"></i>
                    {{ lang('Register') }}
                </a>
            @endif
                <a class="btn btn-default sign-btn no-pjax">
                    <i class="fa fa-user"></i>
                    {{ lang('sign') }}
                </a>
          </ul>
        </div>
      </div>
      <ul class="nav navbar-nav navbar-left {{Auth::check() ? 'navbar-nav-ul-logining' : ''}}">
            <li class="{{ (Request::is('topics') && ! Request::is('categories*') ? ' active' : '') }}"><a href="{{ route('topics.index') }}">{{ lang('Topics') }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.basic_theory_id')) || (isset($topic) && $topic->category_id == config('phphub.basic_theory_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.basic_theory_id')) }}">{{ lang('Basic Theory') }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.speech_application_id')) || (isset($topic) && $topic->category_id == config('phphub.speech_application_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.speech_application_id')) }}">{{ lang('Speech Signal Processing')  }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.image_application_id')) || (isset($topic) && $topic->category_id == config('phphub.image_application_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.image_application_id')) }}">{{ lang('Image Processing')  }}</a></li>
          <li class="{{ (Request::is('categories/'.config('phphub.earthquake_application_id')) || (isset($topic) && $topic->category_id == config('phphub.earthquake_application_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.earthquake_application_id')) }}">{{ lang('Earth Quake Processing')  }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.matlab_algorithm_id')) || (isset($topic) && $topic->category_id == config('phphub.matlab_algorithm_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.matlab_algorithm_id')) }}">{{ lang('Matlab Algorithm') }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.python_algorithm_id')) || (isset($topic) && $topic->category_id == config('phphub.python_algorithm_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.python_algorithm_id')) }}">{{ lang('Python Algorithm') }}</a></li>
            <li class="{{ (Request::is('categories/'.config('phphub.algorithm_sdk_id')) || (isset($topic) && $topic->category_id == config('phphub.algorithm_sdk_id'))) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.algorithm_sdk_id')) }}">{{ lang('Algorithm SDK') }}</a></li>
            {{--<li class="{{ (Request::is('news') ? ' active' : '') }}"><a href="https://dspstack.com/news" class="no-pjax">资讯</a></li>--}}
            <li class="{{ Request::is('categories/'.config('phphub.jobs_id')) || (isset($topic) && $topic->category_id === config('phphub.jobs_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.jobs_id')) }}">{{ lang('Jobs') }}</a></li>
            <li class="{{ Request::is('categories/'.config('phphub.homework_help_id')) || (isset($topic) && $topic->category_id === config('phphub.homework_help_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.homework_help_id')) }}">{{ lang('Homework Help') }}</a></li>
            <li class="{{ Request::is('categories/'.config('phphub.translate_id')) || (isset($topic) && $topic->category_id === config('phphub.translate_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.translate_id')) }}">{{ lang('Translate') }}</a></li>
            <li class="{{ Request::is('categories/'.config('phphub.resources_id')) || (isset($topic) && $topic->category_id === config('phphub.resources_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.resources_id')) }}">{{ lang('Resources') }}</a></li>
            <li class="{{ Request::is('categories/'.config('phphub.hunt_category_id')) || (isset($topic) && $topic->category_id === config('phphub.hunt_category_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.hunt_category_id')) }}">{{ lang('Hunt') }}</a></li>

            {{--<li class="{{ Request::is('categories/'.config('phphub.outsourcing_id')) || (isset($topic) && $topic->category_id === config('phphub.resources_id')) ? ' active' : '' }}"><a href="{{ route('categories.show', config('phphub.outsourcing_id')) }}">{{ lang('Outsourcing') }}</a></li>--}}
            {{--<li class="nav-docs hidden-sm"><a href="http://d.laravel-china.org" class="no-pjax" target="_blank">文档</a></li>--}}
          {{--<li class="hidden-sm"><a href="https://fsdhub.com/books/laravel-essential-training-5.5" class="no-pjax" target="_blank">教程</a></li>--}}
        </ul>
      </div>
  </div>
</div>
@section('scripts')
    <script>
        $(function () {
            $('.sign-btn').click(function () {
                $.ajax({
                    url:"{{url('/users/sign')}}",
                    type:'POST',
                    dataType:'json',
                    data:'',
                    success:function (data) {
                        if(data.status == '-1'){
                            location.href = "{{route('auth.login')}}";
                            return;
                        }
                        if(data.status == '1'){
                            alert(data.msg);
                            return;
                        }else{
                            alert(data.msg);
                            return;
                        }
                    }
                });
            })
        })
    </script>
@stop